#! /bin/sh -e

PREFIX=/usr/local
BIN=$PREFIX/bin
LIB=$PREFIX/lib/fsharp
SHARE=$PREFIX/share/fsharp/
MAN=$PREFIX/share/man/man1/

die()
{
    echo "$1" >&2
    echo "Installation aborted." >&2
    exit 1
}

echo "This script will install F# in $BIN (root access needed)"
echo "Please note this installation is not required for using F#"
echo "but it might improve user-experience."
echo
echo "Press enter to continue."

read a

[ $(id -u) -eq 0 ] || die "Please run the script as root."

which mono > /dev/null || die "mono not found in PATH."

mkdir -p $BIN
mkdir -p $LIB
mkdir -p $SHARE
mkdir -p $MAN

cp script/* $BIN
cp bin/* $LIB
cp uninstall.sh $LIB
cp *.1 $MAN
cp -r samples/* $SHARE/
gacutil -i $LIB/FSharp.Core.dll
gacutil -i $LIB/FSharp.Compiler.dll
gacutil -i $LIB/FSharp.Compiler.Server.Shared.dll
